import 'package:flutter/material.dart';
import 'package:flutterhello/pages/chat_detail/chat_detail.dart';
import 'package:flutterhello/util/host_util.dart';
import 'package:get/get.dart';

class ChatCard extends StatefulWidget {
  var info;
  MessageEntity showMsg;
  ChatCard({this.info, this.showMsg});
  @override
  _ChatCardState createState() => _ChatCardState();
}

class _ChatCardState extends State<ChatCard> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        height: 80,
        width: double.infinity,
        decoration: BoxDecoration(color: Colors.white),
        child: Padding(
          padding: EdgeInsets.only(left: 15),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                width: 55,
                height: 55,
                child: ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                    child: Image.network(
                      HostUtil.getHost() + widget.info['favicon'],
                      fit: BoxFit.cover,
                    )),
              ),
              SizedBox(
                width: 15,
              ),
              Expanded(
                  child: Container(
                decoration: BoxDecoration(
                    border: Border(
                        bottom: BorderSide(color: Colors.black12, width: 0.5))),
                child: Padding(
                  padding:
                      EdgeInsets.only(left: 0, right: 15, top: 15, bottom: 15),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                          child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            widget.info['groupname'],
                            style: TextStyle(fontSize: 16),
                          ),
                          Text(
                            widget.showMsg.msg,
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyle(color: Colors.black45),
                          )
                        ],
                      )),
                      SizedBox(
                        width: 10,
                      ),
                      Container(
                        child: Column(
                          children: [
                            Text(
                              widget.showMsg.time,
                              style: TextStyle(
                                  color: Colors.black38, fontSize: 12),
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              ))
            ],
          ),
        ),
      ),
      onTap: () {
        Get.toNamed('/chat_detail', arguments: widget.info);
      },
    );
  }
}
